-
Notifications
You must be signed in to change notification settings - Fork 50
Extend profiler toolbar item #135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks very cool, thanks a lot! i tried to find where x-duration comes from, but don't find that in the php-http codebase.
Collector/StackPlugin.php
Outdated
|
||
$this->collector->addStack($stack); | ||
|
||
return $next($request)->then(function (ResponseInterface $response) use ($stack) { | ||
$stack->setResponse($this->formatter->formatResponse($response)); | ||
$stack->setResponseCode($response->getStatusCode()); | ||
|
||
if ($response->hasHeader('X-Duration')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where does the x-duration header come from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, now i got it, this depends on php-http/stopwatch-plugin#3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. Thanks!
Is it ready for merge?
@Nyholm it depends on php-http/stopwatch-plugin#3 and we currently are trying to figure out how to track requests and responses in the plugin chain... |
What do you thing about removing the stopwatch plugin from the profiled stacks and directly use the stopwatch component in the public function handleRequest(RequestInterface $request, callable $next, callable $first)
{
$stack = new Stack(
$this->client,
$request->getMethod(),
$request->getRequestTarget(),
$this->formatter->formatRequest($request)
);
$this->collector->addStack($stack);
$eventName = sprintf('%s %s', $request->getMethod(), $request->getUri()->__toString());
$event = $this->stopwatch->start($eventName, 'php_http.request');
return $next($request)->then(function (ResponseInterface $response) use ($stack, $event) {
$stack->setResponse($this->formatter->formatResponse($response));
$stack->setResponseCode($response->getStatusCode());
$event->stop();
$stack->setDuration($event->getDuration());
return $response;
}, function (Exception $exception) use ($stack) {
$stack->setResponse($this->formatter->formatException($exception));
$stack->setFailed(true);
$event->stop();
$stack->setDuration($event->getDuration());
throw $exception;
});
} Such implementation does not require changes neither in symfony nor in the stopwatch plugin :) |
@fbourigault yes, would be an easy solution and more convincing than extending symfony's stopwatch. thanks :) |
i think using the stopwatch directly instead of the plugin sounds better to me. much less complicated and achieves the same functionality in a clean way. at that point we would not need the stopwatch plugin for the bundle at all anymore, right? |
The dependency will still be required. See https://github.com/php-http/HttplugBundle/blob/master/DependencyInjection/HttplugExtension.php#L185-L187. |
oh good. then we don't need to decide if it would be a BC break to change the dependency... |
alright, great! :) i'll take care of this the next days |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is what I did on my laptop: master...fbourigault:profile-client
This is a work in progress and I didn't tested how it operates with discovery.
Collector/StackPlugin.php
Outdated
$stack = new Stack( | ||
$this->client, | ||
$request->getMethod(), | ||
$request->getRequestTarget(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't better to track the request target closer to the client? Plugins may change the target (BaseUrlPlugin
). I have on my laptop something equivalent to improve the profiler display.
Collector/StackPlugin.php
Outdated
|
||
$this->collector->addStack($stack); | ||
|
||
return $next($request)->then(function (ResponseInterface $response) use ($stack) { | ||
$stack->setResponse($this->formatter->formatResponse($response)); | ||
$stack->setResponseCode($response->getStatusCode()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same happens here. Tracking close to the client avoid the ErrorPlugin
to transform 4xx
and 5xx
errors to exceptions.
I've added this to the 1.5 milestone. Can you see why the tests are failing? |
Could you also rebase your branch to get thinks working with |
rebase is done and tests are not failing anymore. (honestly no clue what happened there.) any ideas how to deal with the stopwatch-plugin? i think we need to disabled or even remove it because it interferes with the current implementation. but we could also stop using |
About the stopwatch, I would remove the plugin and mesure time in the StackPlugin. EDIT: to be more accurate, measuring in the ProfileClient will give us the time it took in the low level client (i.e. excluding plugin time execution). Measuring in the StackPlugin will give us the time it took with the plugins. Maybe it worth having both to display more data to the user! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Collector/ProfileClient.php
Outdated
$this->collectExceptionInformations($exception, $stack); | ||
return $response; | ||
}, function (\Exception $exception) use ($event, $stack) { | ||
$this->collectExceptionInformations($exception, $event, $stack); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we call $event->stop()
here?
Collector/ProfileClient.php
Outdated
*/ | ||
private function getStopwatchEventName(RequestInterface $request) | ||
{ | ||
return sprintf('%s %s', $request->getMethod(), $request->getUri()->__toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The -->toString()
is useless as %s
will cast the URI as string.
@fbourigault Thanks for your review! i wasn't able to reproduce your issues exactly but i had quite similar effects caused by duplicate stopwatch event names, so i improved |
Collector/Collector.php
Outdated
/** | ||
* @return int | ||
*/ | ||
public function getDurationSum() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we call this getTotalDuration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great job!
Thank you @chr-hertel. |
Depends on stopwatch plugin PR
What's in this PR?
Extended profiler toolbar item to display more details and duration